﻿using System.Globalization;
using System.Linq;
using System.Web;
using Lari.Configuration;

namespace Lari.Framework.Utility
{
    public static class AccessCheck
    {
        public static bool HasAccess(int accessId)
        {
            var cookie = HttpContext.Current.Request.Cookies[CookieName.AccessCsv];
            if (cookie != null)
            {
                var accessCsv = Encryption.Decrypt(cookie.Value);
                if (string.IsNullOrEmpty(accessCsv))
                {
                    return false;
                }
                var list = accessCsv.Split(',');
                if (!list.Any(s => s == accessId.ToString(CultureInfo.InvariantCulture)))
                {
                    return false;
                }
                return true;
            }

            return false;
        }
    }
}
